Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 3 - Geometric Styles / Using Geometric Styles


Determining Pattern Positions

As with the model for dashes, the QuickDraw GX model for patterns provides only for the case where the pattern shape remains the same throughout the entire patterned shape. If you want to pattern a shape and have the pattern change throughout it, you must use the GXGetShapePatternPositions function. This function returns an array of points that identify the location of each pattern shape on the patterned shape.

As an example, the sample function in this section shows you how to alter the patterned rectangle from the previous section. The sample function in Listing 3-20 first creates the patterned rectangle shown in Figure 3-75 and then uses the GXGetShapePatternPositions function to find the position of each small square in that patterned rectangle. The sample function then creates a picture, adding small squares at the appropriate positions, but rotating each new square a small amount.

Listing 3-20 Changing a pattern throughout a patterned shape

void CreateBizarrePattern(void)
{
   gxShape aRectangleShape, smallRectangle, aPicture;

   static gxRectangle rectangleGeometry = {ff(50), ff(50), 
                                           ff(250), ff(150)};

   static gxRectangle smallRectGeometry = {ff(0), ff(0), 
                                           ff(10), ff(10)};
            
   gxPatternRecord thePatternRecord;

   gxPoint *patternPositions;

   int numberOfPatterns, count;
   
   
   aRectangleShape = GXNewRectangle(&rectangleGeometry);
   GXSetShapeFill(aRectangleShape, gxEvenOddFill);

   smallRectangle = GXNewRectangle(&smallRectGeometry);
   GXSetShapeFill(smallRectangle, gxEvenOddFill);
      
   thePatternRecord.attributes = gxPortAlignPattern;
   thePatternRecord.pattern = smallRectangle;
   thePatternRecord.u.x = ff(0);
   thePatternRecord.u.y = ff(20);
   thePatternRecord.v.x = ff(20);
   thePatternRecord.v.y = ff(0);

   GXSetShapePattern(aRectangleShape, &thePatternRecord);
   
   numberOfPatterns = GXGetShapePatternPositions(aRectangleShape,
                                                 nil);
   patternPositions = (gxPoint *) 
                       NewPtr(numberOfPatterns * sizeof(gxPoint));
   GXGetShapePatternPositions(aRectangleShape, patternPositions);
   
   GXDisposeShape(aRectangleShape);
         
   aPicture = GXNewShape(gxPictureType);
   GXSetShapeAttributes(aPicture, gxUniqueItemsShape);
   for (count = 0; count < numberOfPatterns; count++) {
      GXRotateShape(smallRectangle, ff(10), 0, 0);
      GXMoveShapeTo(smallRectangle, patternPositions[count].x,
                    patternPositions[count].y);
      AddToShape(aPicture, smallRectangle);
   }
   GXDisposeShape(smallRectangle);
   DisposePtr((Ptr)patternPositions);
   
   GXDrawShape(aPicture);
   
   GXDisposeShape(aPicture);
}
This function calls the GXGetShapePatternPositions function twice. The first time, it sends nil as the value of the pattern positions array, which indicates that the GXGetShapePatternPositions function should not return an actual array of positions, but should return as the function result the total number of pattern positions. Once the sample function has this total, it allocates enough memory to hold the array of pattern positions, and then calls GXGetShapePatternPositions again to determine the actual positions.

The result of this sample function is shown in Figure 3-77.

Figure 3-77 Shape with changing pattern

Notice that, in this case, the list of positions returned by GXGetShapePatternPositions starts at the upper-left corner and
works down each column of the patterned shape. In general, the order of
the positions returned by the GXGetShapePatternPositions function is not guaranteed by QuickDraw GX.

This sample function uses some concepts from other parts of QuickDraw GX. For more information about


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help